package com.wolfking.demo.nio.netty;

import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

public class SocketHttp {
    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(9999);
        while (true) {
            Socket accept = serverSocket.accept();
            if (accept != null) {
                TimeUnit.MILLISECONDS.sleep(100);
                InputStream inputStream = accept.getInputStream();
                int available = inputStream.available();
                byte[] request = new byte[available];
                inputStream.read(request, 0, available);
                System.out.println(new String(request, StandardCharsets.UTF_8));
                inputStream.close();
                accept.close();
                System.out.println("************************************************************");
            }
        }
    }
}
